<?php

namespace Wap\Controller;

class MemberController extends WapController {

    //会员登录
    public function register() {
        //判断该用户是否已经注册过了
        $mem = $this->member;
        $where["wechat"] = array("eq", $mem["wechat"]);
        $where["name"] = array("eq", "");
        $where["phone"] = array("eq", "");
        $members = M("members");
            if (IS_POST) {

                $date = array(
                    "name" => I("name"),
                    "phone" => I("phone")
                );
                $where1["wechat"] = array("eq", $mem["wechat"]);
                $result = $members->where($where1)->save($date);
                if ($result) {
                    $this->redirect("center");
                } else {
                    $this->display();
                }
            } else {
                $where1["id"] = array("eq",$mem["id"]);
                $info = $members->where($where1)->find();
                $this->assign("info",$info);
                $this->display();
            }
    }

    //会员中心
    public function center() {
        $this->assign("info",$this->member);
        $this->display();
    }

    //会员卡
    public function card(){
        $mem = $this->member;
        $where["id"] =array("eq",$mem["id"]);
        $info = M("members")->where($where)->find();
        $collectNum = M('collect')->where(array('mid'=>$mem['id'],"type"=>2))->count();
        $info['collectNum'] = $collectNum;
        $this->assign("info",$info);
        $this->display();
    }

}
